String clazzTpl({package}) => """
import 'dart:io';
import 'dart:convert';
import 'package:dio/dio.dart';
import 'api_interface.api.dart';
import 'package:xanno/xanno.dart';
import 'entity/base_entity.api.dart';
import 'manager/http_manager.api.dart';
import 'package:http_parser/http_parser.dart' show MediaType;

class ApiFactory extends ApiInterface {
  ApiFactory({this.host}) {
    host ??= 'https://api.muxiaoguo.cn/api/';
  }

  String? host;

  @override
  Future<List<dynamic>> getTags(CancelToken cancelReq) async {
    const extra = <String, dynamic>{'extraKey': 1, 'extraKey2': '2'};
    final queryParameters = <String, dynamic>{};
    final data = <String, dynamic>{};
    final resp = await HttpManager(host: host!).request<dynamic>('/tags',
        queryParameters: queryParameters,
        options:
            Options(method: 'GET', headers: <String, dynamic>{}, extra: extra),
        data: data,
        cancelToken: cancelReq);
    if (resp.data is BaseEntity) {
      return resp.data.data as List<dynamic>;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as List<dynamic>;
      }
    }
  }

  @override
  Stream<List<String>> getTagsAsStream() async* {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = <String, dynamic>{};
    final resp = await HttpManager(host: host!).request<String>('/tags',
        queryParameters: queryParameters,
        options:
            Options(method: 'GET', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      yield resp.data.data as List<String>;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        yield resp.data as List<String>;
      }
    }
  }

  @override
  Future<List<dynamic>> getTasks() async {
    const extra = <String, dynamic>{'isLoading': true};
    final queryParameters = <String, dynamic>{};
    final data = <String, dynamic>{};
    final resp = await HttpManager(host: host!).request<dynamic>('/tasks',
        queryParameters: queryParameters,
        options:
            Options(method: 'GET', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as List<dynamic>;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as List<dynamic>;
      }
    }
  }

  @override
  Future<dynamic> getTask(String id) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = <String, dynamic>{};
    final resp = await HttpManager(host: host!).request<dynamic>('/tasks/\$id',
        queryParameters: queryParameters,
        options:
            Options(method: 'GET', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as dynamic;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as dynamic;
      }
    }
  }

  @override
  Future<dynamic> updateTaskPart(String id, Map<String, dynamic> map) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = <String, dynamic>{};
    data.addAll(map);
    data.removeWhere((k, v) => v == null);
    final resp = await HttpManager(host: host!).request<dynamic>('/tasks/\$id',
        queryParameters: queryParameters,
        options: Options(
            method: 'PATCH', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as dynamic;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as dynamic;
      }
    }
  }

  @override
  Future<dynamic> updateTask(String id, dynamic task) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = task;
    final resp = await HttpManager(host: host!).request<dynamic>('/tasks/\$id',
        queryParameters: queryParameters,
        options:
            Options(method: 'PUT', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as dynamic;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as dynamic;
      }
    }
  }

  @override
  Future<void> deleteTask(String id) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = <String, dynamic>{};
    await HttpManager(host: host!).request<void>('/tasks/\$id',
        queryParameters: queryParameters,
        options: Options(
            method: 'DELETE', headers: <String, dynamic>{}, extra: extra),
        data: data);
  }

  @override
  Future<dynamic> createTask(dynamic task) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = task;
    final resp = await HttpManager(host: host!).request<dynamic>('/tasks',
        queryParameters: queryParameters,
        options:
            Options(method: 'POST', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as dynamic;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as dynamic;
      }
    }
  }

  @override
  Future<List<dynamic>> createTasks(List<dynamic> tasks) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = tasks.map((e) => e.toJson()).toList();
    final resp = await HttpManager(host: host!).request<dynamic>('/tasks',
        queryParameters: queryParameters,
        options:
            Options(method: 'POST', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as List<dynamic>;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as List<dynamic>;
      }
    }
  }

  @override
  Future<List<String>> createTaskNames(List<String> tasks) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = tasks.map((e) => e).toList();
    final resp = await HttpManager(host: host!).request<String>('/tasks',
        queryParameters: queryParameters,
        options:
            Options(method: 'POST', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as List<String>;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as List<String>;
      }
    }
  }

  @override
  Future<void> createNewTaskFromFile(File file) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = FormData();
    data.files.add(MapEntry(
        'file',
        MultipartFile.fromFileSync(file.path,
            filename: file.path.split(Platform.pathSeparator).last)));
    await HttpManager(host: 'http://httpbin.org/post').request<void>('',
        queryParameters: queryParameters,
        options:
            Options(method: 'POST', headers: <String, dynamic>{}, extra: extra),
        data: data);
  }

  @override
  Future<List<int>> getFile() async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = <String, dynamic>{};
    final resp = await HttpManager(host: 'http://httpbin.org/image/jpeg')
        .request<int>('',
            queryParameters: queryParameters,
            options: Options(
                method: 'GET',
                headers: <String, dynamic>{r'accept': 'image/jpeg'},
                extra: extra,
                responseType: ResponseType.bytes),
            data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as List<int>;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as List<int>;
      }
    }
  }

  @override
  Future<String> postUrlEncodedFormData(String hello, {String? gg}) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    queryParameters.removeWhere((k, v) => v == null);
    final data = {'hello': hello, 'gg': gg};
    data.removeWhere((k, v) => v == null);
    final resp = await HttpManager(host: 'http://httpbin.org/post')
        .request<String>(
            '',
            queryParameters: queryParameters,
            options: Options(
                method: 'POST',
                headers: <String, dynamic>{},
                extra: extra,
                contentType: 'application/x-www-form-urlencoded'),
            data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as String;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as String;
      }
    }
  }

  @override
  Future<String> headRequest() async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = <String, dynamic>{};
    final resp = await HttpManager(host: host!).request<String>('/',
        queryParameters: queryParameters,
        options:
            Options(method: 'HEAD', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as String;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as String;
      }
    }
  }

  @override
  Future<dynamic> headRquest2() async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = <String, dynamic>{};
    final resp = await HttpManager(host: host!).request<dynamic>('/',
        queryParameters: queryParameters,
        options:
            Options(method: 'HEAD', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as dynamic;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as dynamic;
      }
    }
  }

  @override
  Future<HttpResponse<dynamic>> headRquest3() async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = <String, dynamic>{};
    final resp = await HttpManager(host: host!).request<dynamic>('/',
        queryParameters: queryParameters,
        options:
            Options(method: 'HEAD', headers: <String, dynamic>{}, extra: extra),
        data: data);
    return HttpResponse<dynamic>(resp.data, resp);
  }

  @override
  Future<List<dynamic>> grouppedTaskByDate() async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = <String, dynamic>{};
    final resp = await HttpManager(host: host!).request<dynamic>('/task/group',
        queryParameters: queryParameters,
        options:
            Options(method: 'GET', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as List<dynamic>;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as List<dynamic>;
      }
    }
  }

  @override
  Future<HttpResponse<List<dynamic>>> getTasksWithReponse() async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = <String, dynamic>{};
    final resp = await HttpManager(host: host!).request<dynamic>('/task',
        queryParameters: queryParameters,
        options:
            Options(method: 'GET', headers: <String, dynamic>{}, extra: extra),
        data: data);
    return HttpResponse<List<dynamic>>(resp.data, resp);
  }

  @override
  Future<HttpResponse<dynamic>> deleteTaskWithResponse(String id) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = <String, dynamic>{};
    final resp = await HttpManager(host: host!).request<void>('/tasks/\$id',
        queryParameters: queryParameters,
        options: Options(
            method: 'DELETE', headers: <String, dynamic>{}, extra: extra),
        data: data);
    return HttpResponse<dynamic>(resp.data, resp);
  }

  @override
  Future<String> postFormData(dynamic task, {File? file}) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    queryParameters.removeWhere((k, v) => v == null);
    final data = FormData();
    data.fields.add(MapEntry('task', task));
    if (file != null) {
      data.files.add(MapEntry(
          'file',
          MultipartFile.fromFileSync(file.path,
              filename: file.path.split(Platform.pathSeparator).last)));
    }
    final resp = await HttpManager(host: host!).request<String>('/post',
        queryParameters: queryParameters,
        options:
            Options(method: 'POST', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as String;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as String;
      }
    }
  }

  @override
  Future<String> postFormData2(
      List<Map<String, dynamic>> task, List<String> tags, File file) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = FormData();
    for (var i in task) {
      data.fields.add(MapEntry('task', jsonEncode(i)));
    }
    for (var i in tags) {
      data.fields.add(MapEntry('tags', jsonEncode(i)));
    }
    data.files.add(MapEntry(
        'file',
        MultipartFile.fromFileSync(file.path,
            filename: file.path.split(Platform.pathSeparator).last,
            contentType: MediaType.parse('application/json'))));
    final resp = await HttpManager(host: host!).request<String>('/post',
        queryParameters: queryParameters,
        options:
            Options(method: 'POST', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as String;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as String;
      }
    }
  }

  @override
  Future<String> postFormData3({List<File>? files, File? file}) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    queryParameters.removeWhere((k, v) => v == null);
    final data = FormData();
    if (files != null) {
      data.files.addAll(files.map((i) => MapEntry(
          'customfiles',
          MultipartFile.fromFileSync(
            i.path,
            filename: i.path.split(Platform.pathSeparator).last,
            contentType: MediaType.parse('application/json'),
          ))));
    }
    if (file != null) {
      data.files.add(MapEntry(
          'file',
          MultipartFile.fromFileSync(file.path,
              filename: file.path.split(Platform.pathSeparator).last)));
    }
    final resp = await HttpManager(host: host!).request<String>('/post',
        queryParameters: queryParameters,
        options:
            Options(method: 'POST', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as String;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as String;
      }
    }
  }

  @override
  Future<String> postFormData6(
      {List<List<int>>? files, List<int>? file}) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    queryParameters.removeWhere((k, v) => v == null);
    final data = FormData();
    if (files != null) {
      data.files.addAll(files.map((i) => MapEntry(
          'customfiles',
          MultipartFile.fromBytes(
            i,
          ))));
    }
    if (file != null) {
      data.files.add(MapEntry(
          'file',
          MultipartFile.fromBytes(
            file,
            filename: null,
          )));
    }
    final resp = await HttpManager(host: host!).request<String>('/post',
        queryParameters: queryParameters,
        options:
            Options(method: 'POST', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as String;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as String;
      }
    }
  }

  @override
  Future<String> postFormData4(List<dynamic> tasks, File file) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = FormData();
    data.files.add(MapEntry(
        'file',
        MultipartFile.fromFileSync(file.path,
            filename: file.path.split(Platform.pathSeparator).last)));
    final resp = await HttpManager(host: host!).request<String>('/post',
        queryParameters: queryParameters,
        options:
            Options(method: 'POST', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as String;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as String;
      }
    }
  }

  @override
  Future<String> postFormData5(
      List<dynamic> tasks, Map<String, dynamic> map, int a,
      {bool? b, double? c, String? d}) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    queryParameters.removeWhere((k, v) => v == null);
    final data = FormData();
    data.fields.add(MapEntry('map', jsonEncode(map)));
    data.fields.add(MapEntry('a', a.toString()));
    if (b != null) {
      data.fields.add(MapEntry('b', b.toString()));
    }
    if (c != null) {
      data.fields.add(MapEntry('c', c.toString()));
    }
    if (d != null) {
      data.fields.add(MapEntry('d', d));
    }
    final resp = await HttpManager(host: host!).request<String>('/post',
        queryParameters: queryParameters,
        options:
            Options(method: 'POST', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as String;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as String;
      }
    }
  }

  @override
  Future<String> queries(Map<String, dynamic> queries) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    queryParameters.addAll(queries);
    final data = <String, dynamic>{};
    final resp = await HttpManager(host: host!).request<String>('/demo',
        queryParameters: queryParameters,
        options:
            Options(method: 'GET', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as String;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as String;
      }
    }
  }

  @override
  Future<String> queryByEnum(dynamic query) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{r'tasks': null};
    final data = <String, dynamic>{};
    final resp = await HttpManager(host: host!).request<String>('/enums',
        queryParameters: queryParameters,
        options:
            Options(method: 'GET', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as String;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as String;
      }
    }
  }

  @override
  Future<String> namedExample(String apiKey, String scope, String type,
      {int? from}) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{
      r'apikey': apiKey,
      r'scope': scope,
      r'type': type,
      r'from': from
    };
    queryParameters.removeWhere((k, v) => v == null);
    final data = <String, dynamic>{};
    final resp = await HttpManager(host: host!).request<String>('/get',
        queryParameters: queryParameters,
        options:
            Options(method: 'GET', headers: <String, dynamic>{}, extra: extra),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as String;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as String;
      }
    }
  }

  @override
  Future<String> postFile(
      {File? file,
      dynamic Function(int, int)? sendProgress,
      dynamic Function(int, int)? receiveProgress}) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    queryParameters.removeWhere((k, v) => v == null);
    dynamic data;
    if (file != null) {
      data = Stream.fromIterable(file.readAsBytesSync().map((i) => [i]));
    }
    final resp = await HttpManager(host: host!).request<String>('/postfile',
        queryParameters: queryParameters,
        options: Options(
            method: 'POST',
            headers: <String, dynamic>{
              r'Content-Type': 'application/octet-stream',
              r'Ocp-Apim-Subscription-Key': 'abc'
            },
            extra: extra,
            contentType: 'application/octet-stream'),
        data: data,
        onSendProgress: sendProgress,
        onReceiveProgress: receiveProgress);
    if (resp.data is BaseEntity) {
      return resp.data.data as String;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as String;
      }
    }
  }

  @override
  Future<String> testCustomOptions(Options options) async {
    const extra = <String, dynamic>{};
    final queryParameters = <String, dynamic>{};
    final data = <String, dynamic>{};
    if (options.extra != null) {
      options.extra!.addAll(extra);
    }
    if (options.headers != null) {
      options.headers!.addAll(<String, dynamic>{});
    }
    final resp = await HttpManager(host: host!).request<String>('',
        queryParameters: queryParameters,
        options: options.copyWith(method: 'GET'),
        data: data);
    if (resp.data is BaseEntity) {
      return resp.data.data as String;
    } else {
      if (resp.data is DioError) {
        throw resp.data;
      } else {
        return resp.data as String;
      }
    }
  }
}
""";
